package com.cloudxingkong.dianyinke.Student.Ui;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.cloudxingkong.dianyinke.NewTeacher.Utils.WordWrapView;
import com.cloudxingkong.dianyinke.R;
import com.nostra13.universalimageloader.core.ImageLoader;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 预约详情
 */
public class MyAppointmentDetail extends AppCompatActivity {
	private TextView name, titles, contents, times, myAppointment_jsjj, myAppointment_kcap, myAppointment_skdd, yyxq_yishiyong;
	private Button button;
	private CircleImageView yyxq_pic;
	private WordWrapView wwv;
	private String content;
	private String title;
	private String pic;
	private String price;
	private String time;
	private String workepc;
	private String note;
	private String addr;
	private String isuse;
	private String teacherId;
	private String lessonId;
	private String id;

	@Override
	protected void onCreate (Bundle savedInstanceState) {
		super.onCreate (savedInstanceState);
		setContentView (R.layout.activity_my_appointment_detail);
		init ();
		//再次购买
		button.setOnClickListener (new View.OnClickListener () {
			@Override
			public void onClick (View v) {
				new AlertDialog.Builder (MyAppointmentDetail.this)
						.setTitle ("购买提示")//设置对话框标题
						.setMessage ("您确定要再次购买我们的课程吗？")//设置显示的内容
						.setPositiveButton ("确定", new DialogInterface.OnClickListener () {
							@Override
							public void onClick (DialogInterface dialog, int which) {//确定按钮的响应事件

								Intent entity = new Intent (MyAppointmentDetail.this, ConfirmOrder.class);
								entity.putExtra ("teacherPic", pic);
								entity.putExtra ("title", title);
								entity.putExtra ("content", content);
								entity.putExtra ("price", price);
								entity.putExtra ("teacherID", teacherId);
								entity.putExtra ("lessonID", lessonId);
								startActivity (entity);

							}

						}).setNegativeButton ("返回", new DialogInterface.OnClickListener () {//添加返回按钮


					@Override

					public void onClick (DialogInterface dialog, int which) {//响应事件

						Log.i ("alertdialog", " 请保存数据！");

					}

				}).show ();//在按键响应事件中显示此对话框

			}
		});

	}

	private void init () {
		yyxq_pic = (CircleImageView) findViewById (R.id.yyxq_pic);
		name = (TextView) findViewById (R.id.yyxq_name);
		titles = (TextView) findViewById (R.id.yyxq_title);
		contents = (TextView) findViewById (R.id.yyxq_content);
		wwv = (WordWrapView) findViewById (R.id.yyxq_wwv);//标签
		times = (TextView) findViewById (R.id.yyxq_time);
		yyxq_yishiyong = (TextView) findViewById (R.id.yyxq_yishiyong);//使用状态
		myAppointment_jsjj = (TextView) findViewById (R.id.myAppointment_jsjj);
		myAppointment_kcap = (TextView) findViewById (R.id.myAppointment_kcap);
		myAppointment_skdd = (TextView) findViewById (R.id.myAppointment_skdd);

		button = ((Button) findViewById (R.id.btn_zaicigoumai));
		//Intent 接受数据并显示
		Intent intent = getIntent ();
		//老师id
		teacherId = intent.getStringExtra ("teacherID");
		//课程id
		lessonId = intent.getStringExtra ("lessonID");
		isuse = intent.getStringExtra ("isuse");//使用状态

		price = intent.getStringExtra ("price");//单价
		String memname = intent.getStringExtra ("memname");//老师名字
		name.setText (memname);
		title = intent.getStringExtra ("title");
		titles.setText (title);

		pic = intent.getStringExtra ("pic");

		ImageLoader.getInstance ().displayImage (pic, yyxq_pic);

		String label = intent.getStringExtra ("label");//标签
		if (label != null) {
			String[] split = label.split (",");
			for (int i = 0; i < split.length; i++) {
				TextView tv = new TextView (getApplication ());
				tv.setGravity (Gravity.CENTER);
				tv.setTextColor (getResources ().getColor (R.color.white));
				tv.setBackgroundResource (R.drawable.shape_uw_label_main);
				tv.setText (split[i]);
				if (wwv.getChildCount () < split.length) {
					wwv.addView (tv);
				}
				Log.e ("test", wwv.getChildCount () + " -- " + split.length + " -- " + split[i] + " --- " + tv.getText ());
			}
		} else {
			Log.e ("test", "标签为空");
		}
		content = intent.getStringExtra ("content");
		contents.setText (content);
		String serverTime = intent.getStringExtra ("time");
		Log.e ("test", "动态列表中的时间  " + serverTime);
		String ts = serverTime.substring (0, 10);      //截取
		times.setText (ts);     //给day添加数据
		myAppointment_jsjj.setText (intent.getStringExtra ("workepc"));
		myAppointment_kcap.setText (intent.getStringExtra ("note"));
		myAppointment_skdd.setText (intent.getStringExtra ("addr"));
	}

	//返回按钮
	public void back (View view) {
		finish ();
	}

	//评价
	public void btn_evaluate (View view) {
		Intent intent = new Intent (this, Comment.class);
		intent.putExtra ("lessonid", lessonId);
		intent.putExtra ("id", id);
		startActivity (intent);
	}
}
